package com.info.zhiduoduo.core.dto.alipay;

import com.info.zhiduoduo.repository.entity.crowdsource.CrowdsourceTradeRecordItem;
import com.info.zhiduoduo.repository.entity.order.TradeRecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class AlipayTransferFormBean {
    private int paymentMerchant;
    //业务参考号
    private String tradeNo;
    //金额
    private BigDecimal amount;
    //支付宝账号
    private String identity;
    //支付宝名称
    private String name;
    //交易描述
    private String describe;

    public static AlipayTransferFormBean of(TradeRecord tradeRecord) {
        return new AlipayTransferFormBean()
                .setPaymentMerchant(tradeRecord.getPayId())
                .setAmount(tradeRecord.getTradeamount().setScale(2, RoundingMode.DOWN))
                .setIdentity(tradeRecord.getAcctno())
                .setName(tradeRecord.getAcctname())
                .setTradeNo(tradeRecord.getTradeno())
                .setDescribe(" 支付");
    }
    public static AlipayTransferFormBean of(CrowdsourceTradeRecordItem recordItem, Integer merchantId) {
        return new AlipayTransferFormBean()
                .setPaymentMerchant(merchantId)
                .setAmount(recordItem.getTradeamount().setScale(2, RoundingMode.DOWN))
                .setIdentity(recordItem.getAcctno())
                .setName(recordItem.getAcctname())
                .setTradeNo(recordItem.getTradeNo())
                .setDescribe("智众包支付");
    }
}
